package com.tonyliu;

import com.tonyliu.bean.Person;
import com.tonyliu.config.MainConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainTest {
    public static void main(String[] args) {
        // // 配置文件方式
        // ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
        // Person person = applicationContext.getBean("person",Person.class);
        // System.out.println(person);

        // 注解方式
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
        Person person = applicationContext.getBean(Person.class);
        System.out.println(person);

        String[] namesForType = applicationContext.getBeanNamesForType(Person.class);
        for (String name : namesForType) {
            System.out.println(name);
        }
    }
}
